import java.io.File;

/**
 * @描述：
 * @作者: Mr.huang
 * @创建时间: 2017/8/23 10:13
 * @版本: 1.0
 */

public class DeleteTargetFileMain {

    public static void main(String[] args) {
        File file = new File("G:\\BaiduYunDownload");
        deleteTargetFile(file);
    }

    private static void deleteTargetFile(File file) {
        if(file.isDirectory()){
            if("target".equals(file.getName())){
                System.out.println("删除文件夹："+file.getAbsolutePath());
                deleteAllFilesOfDir(file);
            }else{
               File[] files =  file.listFiles();
                for (int i = 0; i <files.length ; i++) {
                    deleteTargetFile(files[i]);
                }
            }
        }
    }

    public static void deleteAllFilesOfDir(File path) {
        if (!path.exists()) return;
        if (path.isFile()) {
            path.delete();
            return;
        }else{
            File[] files = path.listFiles();
            for (int i = 0; i < files.length; i++) {
                deleteAllFilesOfDir(files[i]);
            }
            path.delete();
        }
    }
}
